import 'package:flutter/material.dart';

class chipDemo extends StatefulWidget {
  @override
  _chipDemoState createState() => _chipDemoState();
}

class _chipDemoState extends State<chipDemo> {
   String chipSelect = 'Nothing';
   String _choice = 'Tree';
   List<String> _selectChip = [];
   List<String> _tags = [
    'Apple',
    'Bananer',
    'Tree'
   ];
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title:Text('chipDemo'),
          elevation: 0.0,
        ),
         body: Container(
         padding: EdgeInsets.all(10),
         child: Column(
         mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[ 
            Wrap(
              spacing:10,
              runSpacing:10,
              children: [
                Chip(label: Text('life')),
                Chip(
                  label: Text('life'),
                  backgroundColor: Colors.yellow,
                ),
                Chip(
                  label: Text('Jerry'),
                  avatar: CircleAvatar(
                    backgroundColor: Colors.red,
                    child: Text('张'),
                  ),
                ),
                Chip(
                  label: Text('Jerry'),
                  avatar: CircleAvatar(
                    //backgroundColor: Colors.red,
                    backgroundImage: NetworkImage('http://3.0.169.87/pxmart_upload/image/15535640628607891.png'),
                  ),
                ),
                Chip(
                  label: Text('Test'),
                  deleteIcon: Icon(Icons.delete),
                  deleteIconColor: Colors.red,
                  deleteButtonTooltipMessage: 'Are you sure?',
                  onDeleted:(){
                  },
                ),
              Divider(
                color: Colors.red,
                height: 10,
              )
              ],
            ),
            Wrap(
              spacing: 10,
              children: _tags.map((e){
                return Chip(
                  label: Text(e),
                  onDeleted:(){
                    setState(() {
                      _tags.remove(e);
                    });
                  },
                );
              }).toList(),
            ),
            Text('$chipSelect'),
            Wrap(
              spacing: 10,
              children: _tags.map((e){
                return ActionChip(
                  label: Text(e),
                  onPressed:(){
                     setState(() {
                        chipSelect = e;
                     });
                  },
                );
              }).toList(),
            ),
           Divider(
                color: Colors.red,
                height: 10,
              ),
           Text('${_selectChip.toString()}'),
            Wrap(
              spacing: 10,
              children: _tags.map((e){
                return FilterChip(
                  label: Text(e),
                  selected: _selectChip.contains(e),
                  onSelected:(value){
                    setState(() {
                      if(_selectChip.contains(e)){
                        _selectChip.remove(e);
                       }else{
                         _selectChip.add(e);
                      }
                    });
                    
                  },
                );
              }).toList(),
            ),
            Text('$_choice'),
            Wrap(
              spacing: 10,
              children: _tags.map((tag){
                return ChoiceChip(
                label: Text(tag),
                selected: _choice == tag,
                selectedColor: Colors.black,
                onSelected:(value){
                    setState(() {
                      _choice = tag;
                    });
                  },
                );
              }).toList(),
            ),
          ],
         ),
        ),
        floatingActionButton: FloatingActionButton(
           child: Icon(Icons.store),
           onPressed:(){
             setState(() {
               _tags = [
                    'Apple',
                    'Bananer',
                    'Tree'
                    ];
              _selectChip =[];
             });
           
        }),
    );
  }
}